﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MWTWorkUnitMgmtTool.DataAccess.TableGatewayRepository;
using MWTWorkUnitMgmtTool.ObjectFactories;
using MWTWorkUnitMgmtTool.BusinessEntities;

namespace MWTWorkUnitMgmtTool.Services
{
    public class ProductionWorkunitService:IProductionWorkUnitService
    {
        private IProductionWorkunitRepository _productionWorkunitRepository;
        
        public ProductionWorkunitService(IProductionWorkunitRepository productionWorkunitRepository)
        {
            _productionWorkunitRepository = productionWorkunitRepository;
           
        }

        #region IProductionWorkUnitService Members

        public IEnumerable<ProductionWorkunit> GetProductionWorkunitsByBOM(string parentItemCode)
        {
            return _productionWorkunitRepository.GetProductionWorkunitsByBOM(parentItemCode).Select(f => ObjectFactory.ProductionWorkunitFactory(f));
        }

        public int AddProductionWorkunit(string wuCode, string wuName, string itemCode, string itemName, string parentItemCode, string facility)
        {
            return _productionWorkunitRepository.AddProductionWorkUnit(wuCode, wuName, itemCode, itemName, parentItemCode, facility);
        }

        public int UpdateProductionWorkunit(string wuCode, string wuName, string itemCode, string itemName, string parentItemCode, string facility)
        {
            return _productionWorkunitRepository.UpdateProductionWorkunit(wuCode, wuName, itemCode, itemName, parentItemCode, facility);
        }

        public int DeleteProductionWorkunitByWUCode(string wuCode)
        {
            return _productionWorkunitRepository.DeleteProductionWorkunitByWUCode(wuCode);
        }

        public IEnumerable<Item> GetAllItems()
        {
            return _productionWorkunitRepository.GetAllItems().Select(f => ObjectFactories.ObjectFactory.ItemFactory(f)); 
        }

        #endregion

    }
}
